package com.salou.cellar.activity.helpers;

import java.util.HashMap;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

import com.salou.cellar.dto.Bottle;

import android.R;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;

/**
 * Filter contain a concept name (label, country etc) and matching icon
 * reference
 * 
 * @author Loic
 */
public class Filter {
	private static Map<String,Filter> instances=new HashMap<String,Filter>();   
	public String name;
	public Drawable icon;
	public boolean isSelectable;
	public boolean isSelected;
	public String value;

	public static Filter getInstance(String name) {
		Filter ret=instances.get(name);
		if (ret==null) {
			ret=new Filter(name, null);
			instances.put(name, ret);
		}
		return ret;
	}
	
	private Filter(String name, Drawable icon) {
		super();
		this.name = name;
		this.icon = icon;
		this.isSelectable = true;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Drawable getIcon() {
		return icon;
	}

	public void setIcon(Drawable icon) {
		this.icon = icon;
	}

	public boolean isSelectable() {
		return isSelectable;
	}

	public void setSelectable(boolean isSelectable) {
		this.isSelectable = isSelectable;
	}

	public boolean isSelected() {
		return isSelected;
	}

	public void setSelected(boolean isSelected) {
		this.isSelected = isSelected;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public String getLabel() {
		try {
			return ResourceBundle.getBundle(Bottle.BUNDLE).getString(name);
		} catch (MissingResourceException e) {
			return "<"+name+">";
		}
	}

	@Override
	public String toString() {
		return getLabel();
	}
}